-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create constructor for creating allocated BlockArrays #39
Conversation
…ocated block arrays • Deprecate BlockArray(blocks,...) in favour of _BlockArray(blocks,...) to avoid confusion with BlockArray(arr,...) function that converts arr to a BlockArray.
This addresses #37 |
We should definitely not export a function with an underscore in it (or is this not exported anymore). Also, why can't we just dispatch on Type vs instance to keep it as one function? Being able to create uninitialized blocks is valuable in my opinion. |
It isn't exported. The issue is that one might want to create a Because I've added allocating constructors, the need for the |
Alternatively, it could be renamed |
Base is doing something like |
Cool! how would I implement that? |
Codecov Report
@@ Coverage Diff @@
## master #39 +/- ##
==========================================
+ Coverage 88.4% 89.58% +1.18%
==========================================
Files 9 9
Lines 345 365 +20
==========================================
+ Hits 305 327 +22
+ Misses 40 38 -2
Continue to review full report at Codecov.
|
|
docs/src/man/blockarrays.md
Outdated
## Creating initialized `BlockArrays` | ||
|
||
A block array can be created with initialized blocks using the `BlockArray{T}(block_sizes)` | ||
function. The block_sizes are each an `AbstractVector{Int}` which determines the size of the blocks in that dimension. We here create a `[1,2]×[3,2]` block matrix of `Float32`s: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should mention that the arrays themselves are initialized, the values in them are not? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this behaviour going to change in 0.7 so that Matrix{Float64}(n,m)
automatically sets the values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it will, but not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused about the difference between Matrix{Float64}(uninitialized, n, m)
and Matrix{Float64}(n, m)
.
I'm worried that there's a confusion between uninitialized blocks and uninitialized entries with using uninitialized
to mean uninitialized blocks. Especially since I'm hoping to making PseudoBlockArray
and BlockArray
have equivalent behaviour for the same syntax.
It might be better to add a UninitializedBlocks
and then we have the following three cases:
BlockArray{Float64}(uninitialized_blocks, ns)
, which does not initialize the blocks, i.e.,A.blocks[1]
is#undef
. This is the current behaviour ofBlockArray(Vector{Float64}, ns)
BlockArray{Float64}(uninitialized, ns)
, which initializes the blocks, but not the entries of the blocks, i.e.,A.blocks[1]
is allocated as aVector{Float64}(uninitialized, ns[1])
BlockArray{Float64}(ns)
, which does initialize the blocks, and the entries, i.e.,A.blocks[1]
is allocated as aVector{Float64}(ns[1])
PseudoBlockArray{Float64}(uninitialized, ns)
,A. blocks
is allocated as aVector{Float64}(uninitialized, sum(ns))
PseudoBlockArray{Float64}(ns)
, which does initialize the blocks, and the entries, i.e.,A.blocks
is allocated as aVector{Float64}(sum(ns))
docs/src/man/blockarrays.md
Outdated
@@ -23,13 +38,13 @@ julia> BlockArray(Matrix{Float32}, [1,2], [3,2]) | |||
We can also use a `SparseVector` or any other user defined array type: | |||
|
|||
```jl | |||
julia> BlockArray(SparseVector{Float64, Int}, [1,2]) | |||
julia> BlockArrays._BlockArray(SparseVector{Float64, Int}, [1,2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be updated to use uninitialized?
@KristofferC The checks now pass, are you happy for this to be merged? |
src/pseudo_blockarray.jl
Outdated
@@ -60,6 +60,32 @@ PseudoBlockArray(blocks::R, block_sizes::Vararg{AbstractVector{Int}, N}) where { | |||
PseudoBlockArray(blocks, Vector{Int}.(block_sizes)...) | |||
|
|||
|
|||
|
|||
@inline function PseudoBlockArray{T}(block_sizes::BlockSizes{N}) where {T, N} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably all these new PseudoBlockArray
constructors should use uninitialized
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think you are right, even if the package supports 0.6.
My only hesitation is that sometimes changes in Julia master are backtracked on, but in this case that’s unlikely to happen.
@@ -1,2 +1,2 @@ | |||
julia 0.6 | |||
Compat 0.30.0 | |||
Compat 0.38.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compat 0.39
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't depend on anything in Compat 0.39 that's not in Compat 0.38, so I think this should be left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compat 0.38 is broken. Please update to 0.39.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote this and then I merged 20 seconds later. Oh well, will update on master.
• Support BlockArray{Float64}(1:3, 1:3), etc. syntax for creating allocated block arrays
• Deprecate BlockArray(blocks,...) in favour of _BlockArray(blocks,...) to avoid confusion with BlockArray(arr,...) function that converts arr to a BlockArray.